/*!
 * \file __frreport_get_ip.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>
#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frxml_parse.h"

#include "conntrack.h"
#include "frmodule_mng.h"
#include "frct_comm.h"
#include "frreport_mng.h"
#include "frversion.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


extern int __frreport_get_ip(Frreport_data *p_st_report_data
        , u_int *p_ui_src_ip, u_short *p_us_src_port
        , u_int *p_ui_dst_ip, u_short *p_us_dst_port);

static void __case1(void)
{
    int i_ret = 0;
    Frreport_data *p_st_report_data = NULL;
    u_int ui_src_ip = 0, ui_dst_ip = 0;
    u_short us_src_port = 0, us_dst_port = 0;
    Frreport_l7data *p_st_l7data = NULL;
    Frreport_body_data st_report_body_data;
    Frlist_node *p_st_node = NULL;

    p_st_report_data = (Frreport_data *)frmalloc (sizeof (Frreport_data));
    memset (p_st_report_data, 0x00, sizeof (Frreport_data));

    p_st_report_data->em_type = FRREPORT_TYPE_L7DATA;

    memset (&st_report_body_data, 0x00, sizeof (Frreport_body_data));
    p_st_l7data = &st_report_body_data.un_data.st_l7data;

    p_st_l7data->src_ip = 19216811;
    p_st_l7data->src_port = 80;
    p_st_l7data->dst_ip = 19216812;
    p_st_l7data->dst_port = 21;

    p_st_node = frlist_node_create (&st_report_body_data);
    frlist_push (&p_st_report_data->st_hdr_body, p_st_node);

    i_ret = __frreport_get_ip(p_st_report_data, &ui_src_ip, &us_src_port, &ui_dst_ip, &us_dst_port);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_src_ip, 19216811);
    CU_ASSERT_EQUAL(us_src_port, 80);
    CU_ASSERT_EQUAL(ui_dst_ip, 19216812);
    CU_ASSERT_EQUAL(us_dst_port, 21);

    frfree (p_st_node);
    frfree (p_st_report_data);

    return;

}

static void __case2(void)
{
    int i_ret = 0;
    Frreport_data *p_st_report_data = NULL;
    u_int ui_src_ip = 0, ui_dst_ip = 0;
    u_short us_src_port = 0, us_dst_port = 0;

    i_ret = __frreport_get_ip(p_st_report_data, &ui_src_ip, &us_src_port, &ui_dst_ip, &us_dst_port);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;

}




int add_suite___frreport_get_ip(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frreport_mng __frreport_get_ip()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);


    return FR_SUCC;
}
